const path = require('path');
const fs = require('fs');
const SetsysController = {};
const templateView = require('../model/template')

//导入模型
const viewsDir = path.join(path.dirname(__dirname), 'views');
const query = require('../model/query.js');

SetsysController.setsys = (req, res) => {
    templateView(res,`system.html`,)
}
SetsysController.logDditPic = async(req,res) => {
    const imgPath = `/uploads/`;
    const imgDirname = `${path.dirname(__dirname)}`;
let pic;
    let { originalname, filename, destination } = req.file;
    // 重命名文件

    fs.rename(path.join(`${imgDirname}${imgPath}${filename}`), path.join(`${imgDirname}${imgPath}${originalname}`), (err) => {
        if (err) console.log(err, 'on');
        console.log('ok');


    });
    pic = imgPath + originalname;
    console.log(pic, 'pic');
    const sqlStr = `UPDATE system set  vaule = '${pic}' WHERE name = 'pic'`;
    let data = await query(sqlStr);
  
    res.send('5tfr')
    // 判断 操作 是否成功
}
// // 添加入口
// systemController.addSystem = (req, res) => {
//     res.render('addSystem.html')
// }

module.exports = SetsysController;